/**
 * file
 */
package com.tdkj.action.front.member.financial;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tdkj.action.BaseAction;
import com.tdkj.model.financial.BeanTransferRecord;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.financial.IBeanTransferRecordService;

/**
 * 
 * FileName: AccountTransferAction.java
 * 
 * @Description: TODO账户转账
 * 
 *               All rights Reserved, Designed By ZTE-ITS
 * 
 *               Copyright: Copyright(C) 2010-2011
 * 
 *               Company 天成科技有限公司
 * 
 * @author: 李兴建
 * 
 * @version V1.0
 * 
 *          Createdate: 2012-5-27 下午02:15:28
 * 
 * 
 * 
 *          Modification History:
 * 
 *          Date Author Version Discription
 * 
 * 
 * 
 *          
 *          ----------------------------------------------------------------------
 *          -------------
 * 
 *          2012-5-27 李兴建 1.0 1.0
 * 
 *          Why & What is modified: <修改原因描述>
 */
public class AccountTransferAction extends BaseAction {
	private static final long serialVersionUID = -445762665833775865L;
	private Integer money;
	private Long toUserId;
	private String unit;
	private String toAccount;
	private List<BeanTransferRecord> historyList;
	
	private IBeanTransferRecordService transferRecordService;
	
	@SuppressWarnings("unchecked")
	@Override
	public String execute() throws Exception {
		Criteria criteria = this.createCriteria(BeanTransferRecord.class);
		criteria.add(Restrictions.eq("user", this.getCurrentUser()));
		criteria.addOrder(Order.desc("dateTime"));
		historyList = criteria.list();
		return super.execute();
	}

	public String transfer() throws Exception {
		BeanUser user = this.getCurrentUser();
		transferRecordService.create(user.getId(), toUserId, money, unit);
		return execute();
	}


	public String getToAccount() {
		return toAccount;
	}

	public void setToAccount(String toAccount) {
		this.toAccount = toAccount;
	}

	public List<BeanTransferRecord> getHistoryList() {
		return historyList;
	}

	public void setHistoryList(List<BeanTransferRecord> historyList) {
		this.historyList = historyList;
	}

	public Integer getMoney() {
		return money;
	}

	public void setMoney(Integer money) {
		this.money = money;
	}

	public Long getToUserId() {
		return toUserId;
	}

	public void setToUserId(Long toUserId) {
		this.toUserId = toUserId;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	@Resource
	public void setTransferRecordService(
			IBeanTransferRecordService transferRecordService) {
		this.transferRecordService = transferRecordService;
	}

	
}
